// 扩展2-3、多维向量
/**
 * 二维向量
 * std::vector<std::vector<int>> vec(10);
 * 
 * 注意内层向量设置size或capacity,at()有越界检查size,[]取下标无越界检查
 * 
 * 三维向量
 * std::vector<std::vector<std::vector<int>>> vec(x);
 */

#include <iostream>
#include <vector>
int main(void)
{
  // 二维向量
  /**
  const int n = 3, m = 4;
  std::vector<std::vector<int>> vec(n);
  for (int i = 0; i < n; i++)
  {
    std::cout << "vec[" << i << "] size: " << vec[i].size() << std::endl;
    // vec[i] = std::vector<int>(m);

    // vec[i].resize(m);
    vec[i].reserve(m);
    for (int j = 0; j < m; j++)
    {
      // vec.at(i).at(j) = i * j;// at会越界检查,size
      vec[i][j] = i * j;
    }
  }

  for (int i = 0; i < n; i++)
  {
    for (int j = 0; j < m; j++)
    {
      std::cout << "vec[" << i << "][" << j << "]: " << vec[i][j] << std::endl;
    }
  }
  */

  // 三维向量
  const int x = 3, y = 4, z = 5;
  std::vector<std::vector<std::vector<int>>> vec(x);
  for (int i = 0; i < x; i++)
  {
    vec[i].resize(y);
    for (int j = 0; j < y; j++)
    {
      vec[i][j].reserve(z);
      for (int k = 0; k < z; k++)
      {
        vec[i][j][k] = i + j + k;
      }
    }
  }

  for (int i = 0; i < x; i++)
  {
    std::cout << "i:" << i << std::endl;

    for (int j = 0; j < y; j++)
    {
      for (int k = 0; k < z; k++)
      {
        std::cout << "vec[" << i << "][" << j << "][" << k << "]: " << vec[i][j][k] << std::endl;
      }
    }
  }

  printf("---------------end------------------\n");
  return 0;
}